package com.maixun.lib_comment.utils

import com.maixun.lib_comment.CommentApplication
import io.reactivex.Observable
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

/**
 * 作者：Lmoumou
 * 时间：2019/8/13 11:28
 */
object AssetsUtil {
    fun getJsonStr(fileName: String): Observable<String> {
        return Observable.create {
            val stringBuilder = StringBuilder()
            try {
                val assetManager = CommentApplication.mContext.assets
                val bf = BufferedReader(InputStreamReader(assetManager.open(fileName)))
                var line: String?

                do {
                    line = bf.readLine()
                    if (line != null) {
                        stringBuilder.append(line)
                    } else {
                        break
                    }
                } while (true)

            } catch (e: IOException) {
                e.printStackTrace()
            }

            it.onNext(stringBuilder.toString())
        }

//        return stringBuilder.toString()
    }
}